<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8" />
	<title>{$lang.add}|{$lang.edit}</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<include file="common/ace-tag"/>
</head>
<link rel="stylesheet" href="/static/plugin/ace/css/chosen.css" />
<script src="/static/plugin/ace/js/chosen.jquery.min.js"></script>
<script src="/static/plugin/ace/js/jquery.autosize.min.js"></script>
<script src="/static/plugin/ace/js/jquery.inputlimiter.1.3.1.min.js"></script>
<style>
	body{
		background-color:#fff
	}
	#content {
		width: 95%;
		height: 300px;
	}
</style>
<body >
<div>
	<div class="layui-form">
		<div class="widget-main">
			<input type="hidden" name="id" value="{$data.id}"/>
			<div>
				<label>{$lang_field['novel.title']}</label>
				<select class="form-control" name="novel_id" lay-filter="novel_id" lay-search>
					<foreach name="novel_list" item="val" key="key">
						<if condition="$data.novel_id==$val.id">
							<option value="{$val.id}" selected>{$val.title}</option>
							<else/>
							<option value="{$val.id}">{$val.title}</option>
						</if>
					</foreach>
				</select>
				<br>
			</div>

			<div>
				<label>{$lang_field['novel_volume.title']}</label>
				<select class="form-control" name="volume_id" lay-search>
					<foreach name="volume_list" item="val" key="key">
						<if condition="$data.volume_id==$val.id">
							<option value="{$val.id}" selected>{$val.title}</option>
							<else/>
							<option value="{$val.id}">{$val.title}</option>
						</if>
					</foreach>
				</select>
				<br>
			</div>

			<div>
				<label >{$lang_field['novel_chapter.title']}</label>
				<input type="text" name="title" placeholder="{$lang_field['novel_chapter.title']}" class="form-control" value="{$data.title}"/>
				<br>
			</div>

			<div>
				<label >{$lang_field.status}</label>
				<select class="form-control" name="status">
					<eq name="data.status|default=1" value="1">
						<option value="1" selected>{$lang_field.on}</option>
						<option value="2">{$lang_field.off}</option>
						<else/>
						<option value="2" selected>{$lang_field.off}</option>
						<option value="1">{$lang_field.on}</option>
					</eq>
				</select>
				<br>
			</div>

			<button class="btn btn-primary" id="yui_save">
				<i class="icon-plus align-top bigger-125"></i>
				{$lang.save}
				<br>
			</button>

			<div style="margin-top: 30px">
				<label >{$lang_field['novel_chapter.content']}</label>
				<textarea id="content">{:htmlspecialchars_decode($data.content)}</textarea>
			</div>

		</div>
	</div>
</div>

</body>
<include file="common/ueditor"/>
<script>
    $(function () {
        $(".chosen-select").chosen();
        ue.ready(function() {
            $("#edui1").css('width','100%');
            $("#edui1_iframeholder").css('width','100%');
        });

        layui.use(['form'], function(){
            let form = layui.form;
            form.on('select(novel_id)', function(data){
                let loading = layer.load(1, {
                    shade: [0.1,'#fff']
                });
                let novel_id =data.value;
                $.post("{$__url}",
                    {
                        novel_id:novel_id,
						change:true,
                    },
                    function(data,status){
                        if (data['code']==1){
                            let volumeList=data['data'];
                            $("select[name='volume_id']").empty();
                            for(let key in volumeList){
                                $("select[name='volume_id']").append("<option value="+volumeList[key]['id']+">"+volumeList[key]['title']+"</option>")
                            }
                            form.render('select');
                        }else{
                            layer.msg(data['msg']);
                        }
                        layer.close(loading);
                    }, "json"
                );
            });
        });

        //新增管理员
        $("#yui_save").on('click' , function(){
            let id=$("input[name='id']").val();
            let novel_id=$("select[name='novel_id']").val();
            let volume_id=$("select[name='volume_id']").val();
            let title=$("input[name='title']").val();
            let content=ue.getContent();
            let status=$("select[name='status']").val();
            if (ue.hasContents()){
                let loading = layer.load(1, {
                    shade: [0.1,'#fff']
                });
                //ajax提交数据
                $.post("{$__url}",
                    {
                        method:'{$method}',
                        id:id,
                        novel_id:novel_id,
                        volume_id:volume_id,
                        title:title,
                        content:content,
                        status:status
                    },
                    function(data,status){
                        if (data['code']==1){
                            layer.open({
                                title: '{$lang.notice}',
                                content: '{$lang.op_success}'
                                ,yes: function(index, layero){
                                    //关闭本子页面 & 触发重新查询
                                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                                    let node = window.parent.document.getElementById("npe_search");
                                    node.click();
                                }
                            });
                        }else{
                            layer.msg(data['msg']);
                        }
                        layer.close(loading);
                    }, "json"
                );
			}else {
                layer.msg("{$lang_field['novel_chapter.validata.content.require']}");
			}
        });

    });
</script>

</html>